<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
Yii::import('zii.widgets.grid.CGridView');
/**
 * Description of RiotingGrid
 *
 * @author Moon
 */
class RiotingGrid extends CGridView {
    //put your code here

    public function init() {
        CBaseListView::init();

        if (!isset($this->htmlOptions['class']))
            $this->htmlOptions['class'] = 'grid-view';

        if ($this->baseScriptUrl === null)
            $this->baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')) . '/gridview';

        if ($this->cssFile !== false && !Yii::app()->request->isAjaxRequest) {
            if ($this->cssFile === null)
                $this->cssFile = $this->baseScriptUrl . '/styles.css';
            Yii::app()->getClientScript()->registerCssFile($this->cssFile);
        }

        $this->initColumns();
    }

    public function registerClientScript() {
        $id = $this->getId();

        if ($this->ajaxUpdate === false)
            $ajaxUpdate = false;
        else
            $ajaxUpdate=array_unique(preg_split('/\s*,\s*/', $this->ajaxUpdate . ',' . $id, -1, PREG_SPLIT_NO_EMPTY));
        $options = array(
            'ajaxUpdate' => $ajaxUpdate,
            'ajaxVar' => $this->ajaxVar,
            'pagerClass' => $this->pagerCssClass,
            'loadingClass' => $this->loadingCssClass,
            'filterClass' => $this->filterCssClass,
            'tableClass' => $this->itemsCssClass,
            'selectableRows' => $this->selectableRows,
        );
        if ($this->beforeAjaxUpdate !== null)
            $options['beforeAjaxUpdate'] = (strpos($this->beforeAjaxUpdate, 'js:') !== 0 ? 'js:' : '') . $this->beforeAjaxUpdate;
        if ($this->afterAjaxUpdate !== null)
            $options['afterAjaxUpdate'] = (strpos($this->afterAjaxUpdate, 'js:') !== 0 ? 'js:' : '') . $this->afterAjaxUpdate;
        if ($this->selectionChanged !== null)
            $options['selectionChanged'] = (strpos($this->selectionChanged, 'js:') !== 0 ? 'js:' : '') . $this->selectionChanged;

        $options = CJavaScript::encode($options);
        $cs = Yii::app()->getClientScript();
        if(!Yii::app()->request->isAjaxRequest) {
            $cs->registerCoreScript('jquery');
            $cs->registerCoreScript('bbq');
            $cs->registerScriptFile($this->baseScriptUrl . '/jquery.yiigridview.js');
        }
        $cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#$id').yiiGridView($options);");
    }
}
?>
